<template>
	<view class="container">
		<u-navbar title-color='#fff' back-icon-color='#fff' height='88' title="菜谱搜索" :background="background"
			:border-bottom='false'>
			<view class="slot-wrap">
				<image src="../../static/image/detail/xuhuan.png"></image>
				<image src="../../static/image/detail/zhuanfa.png"></image>
			</view>
		</u-navbar>

		<view class="" v-if="detailObj.isFree=='N'?false:true">
			<video id="myVideo" :src="detailObj.vid" @error="videoErrorCallback" enable-danmu danmu-btn
				controls></video>
		</view>
		<view class="" v-else>
			<view class="isCover" v-if="!userInfo.vip">
				<navigator url="/pages/getVip/getVip">
					<image :src="detailObj.coverpic" mode=""></image>
					<view class="coverBox">
						<text>开通会员观看视频做法</text>
						<button type="default">立即开通</button>
						<text>已是会员，立即登录 > </text>
					</view>
				</navigator>

			</view>
			<video v-else id="myVideo" :src="detailObj.vid" @error="videoErrorCallback" enable-danmu danmu-btn
				controls></video>
		</view>
		<view class="content">
			<view class="top">
				<navigator class="box1" url="/pages/getVip/getVip">
					<view class="box1">
						<text>会员低至两元/月，免广告、看10000+名厨视频</text>
					</view>
				</navigator>

				<view class="text">
					<text>{{detailObj.name}}</text>
				</view>
				<view class="box2">
					<text>{{detailObj.pageview}}.0万浏览</text>
					<image src="../../static/image/index/like/mengbanzu278.png"></image>
					<text>{{detailObj.collections}}收藏</text>
					<image src="../../static/image/index/like/mengbanzu279(1).png"></image>
				</view>
			</view>
			<view class="colorBox"></view>
			<view class="mid">
				<view class="item" v-for="item in detailObj.tips" :key='item.tipname'>
					<view class="title">
						<text>{{item.tipname}}</text>
					</view>
					<text>{{item.tipdescribe[0]}}</text>
				</view>
			</view>
			<view class="colorBox"></view>
			<view class="bottom">
				<view class="ingredient">
					<view class="head">
						<image src="../../static/image/detail/shijian.png"></image>
						<text>{{detailObj.ingredient.nv_length}}分钟以上</text>
						<image src="../../static/image/detail/xing.png"></image>
						<text>切墩（初级）</text>
					</view>
					<view class="title">
						<text>用料</text>
						<text :class="{a:!isCollect,gray:isCollect}"
							@tap='collect'>{{isCollect?'移除采购清单':'加入采购清单'}}</text>
					</view>
					<view class="item" v-for="item in detailObj.ingredient" :key='item.name'>
						<text>{{item.name}}</text>
						<text>{{item.number}}</text>
					</view>
				</view>
				<view class="stepBox">
					<view class="stepItem" v-for="(item,index) in detailObj.method" :key='index'>
						<text class="title">步骤{{index+1}}</text>
						<image :src="item.img"></image>
						<text>{{item.describe}}</text>
					</view>
				</view>
				<view class="likeBox">
					<text>相关推荐</text>
					<view class="guessUlike">
						<homeLike :likeItem='item' v-for="item in guessUlikeData" :key='item._id' />
					</view>
				</view>

			</view>
		</view>
		<u-back-top :scroll-top="scrollTop"></u-back-top>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					// background: 'url(../../static/image/index/ditu%20.png) no-repeat'
					// 还可以设置背景图size属性
					// backgroundSize: 'cover',
					// 渐变色
					backgroundImage: 'linear-gradient(45deg,  rgb(238,123,45), rgb(247,145,28))'
				},
				detailObj: {},
				guessUlikeData: [],
				scrollTop: 0,
				userInfo: '',
				isCollect: false,
				menu_id: ''

			}
		},
		computed: {
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		methods: {
			getMenuDetail(data) {
				this.$api.search.getMenuDetail(data).then(res => {
					// console.log(res.message[0])
					this.detailObj = res.message[0]
				})
			},
			getRecommend() {
				this.$api.home.getRecommend().then(data => {
					this.guessUlikeData = data.message
					// console.log(data.message);
				})
			},
			collect() {
				const token = uni.getStorageSync('token')
				if (token == '') {
					this.$refs.uToast.show({
						title: '你还没有登录 请先去登录',
						type: 'error',
						url: '/pages/login/index'
					})
				} else {
					this.$api.my.collect({
						user_id: this.userInfo._id,
						menu_id: this.menu_id
					}).then(res => {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'success',
						})
						this.isCollectFun(this.menu_id)
						// console.log(res);
					})
				}

			},
			isCollectFun(id) {
				const token = uni.getStorageSync('token')
				this.$api.login.getUserInfo(token).then(a => {
					// console.log(a[0])
					this.userInfo = a[0]
					this.isCollect = this.userInfo.mycollect.some(v => v == id)
				})

			},
			saveHistory(menu_id) {
				const token = uni.getStorageSync('token')
				this.$api.login.getUserInfo(token).then(a => {
					console.log(a[0])
					let user_id = a[0]._id
					this.$api.my.record({user_id,menu_id}).then(res=>{
						console.log(res);
					}).catch(res=>{
						console.log(res);
					})
				})
			}
		},
		onLoad(options) {
			this.menu_id = options._id
			// 保存浏览记录
			const token = uni.getStorageSync('token')
			if (token) {
				this.saveHistory(this.menu_id)
			}


			this.isCollectFun(options._id)

			this.getMenuDetail(options)
			// this.getMenuDetail({ _id: '601fa488882000007800670c' })
			this.getRecommend()
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		.slot-wrap {
			display: flex;
			padding: 0 30rpx;
			margin-left: 508rpx;
			margin-top: 102rpx;

			image {
				width: 50rpx;
				height: 50rpx;
			}
		}

		.isCover {
			position: relative;

			image {
				width: 750rpx;
				height: 386rpx;
			}

			.coverBox {
				width: 750rpx;
				height: 386rpx;
				background-color: rgba(0, 0, 0, 0.7);
				position: absolute;
				top: 0rpx;
				padding-top: 86rpx;
				text-align: center;

				text {
					font-size: 32rpx;
					color: #F3dfbf;
				}

				button {
					width: 244rpx;
					height: 68rpx;
					line-height: 68rpx;
					background-image: linear-gradient(0deg,
							#f9e9cd 0%,
							#edd6b2 50%,
							#edd6b2 100%);
					border-radius: 34rpx;
					margin-bottom: 30rpx;
					margin-top: 30rpx;
				}
			}
		}

		video {
			width: 750rpx;
			height: 386rpx;
		}

		.content {
			// padding: 26rpx 32rpx;

			>.top {
				width: 750rpx;
				height: 300rpx;
				background-color: #ffffff;
				margin-top: 28rpx;

				>.text {
					font-size: 34rpx;
					font-weight: bold;
					text-align: center;
				}

				>.box1 {
					margin: 0 auto 52rpx;
					width: 686rpx;
					height: 88rpx;
					line-height: 88rpx;
					background-color: #e7b666;
					text-align: center;
					border-radius: 16rpx;

					text {
						font-size: 29rpx;
						color: white;
					}
				}

				>.box2 {
					justify-content: center;
					display: flex;
					align-items: center;
					margin-top: 30rpx;

					text {
						color: #c9c9c9;
						font-size: 18rpx;
						padding: 0 20rpx;

					}

					image {
						width: 24rpx;
						height: 24rpx;
					}
				}
			}

			.colorBox {
				height: 28rpx;
				background-color: #f6f7f8;
			}

			.mid {
				padding: 32rpx;

				>.item {
					font-size: 24rpx;
					margin-bottom: 25rpx;

					.title {
						font-size: 28rpx;
						font-weight: bold;
						margin-bottom: 8rpx;
					}
				}
			}

			.bottom {
				.ingredient {
					padding: 0 52rpx;

					.head {
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 26rpx;
						margin-top: 42rpx;

						text {
							padding: 20rpx;
						}

						image {
							width: 36rpx;
							height: 36rpx;
						}
					}

					.title {
						font-size: 30rpx;
						margin-top: 15rpx;
						line-height: 72rpx;
						display: flex;
						font-weight: bold;
						justify-content: space-between;

						text {
							padding: 20rpx;
						}

						.a {
							color: #f3a56f;
						}

						.gray {
							color: #afafaf;
						}
					}

					.item {
						line-height: 72rpx;
						display: flex;
						justify-content: space-between;
						border-bottom: 1rpx solid #f6f7f8;
					}
				}

				.stepBox {
					padding: 32rpx;

					.stepItem {
						margin-bottom: 48rpx;

						image {
							width: 688rpx;
							height: 440rpx;
							margin-bottom: 34rpx;
							margin-top: 26rpx;
							border-radius: 8rpx;
						}

						.title {
							font-weight: bold;

						}
					}
				}

				.likeBox {
					padding: 32rpx;

					.guessUlike {
						margin-top: 20rpx;
						display: flex;
						justify-content: space-between;
						flex-wrap: wrap;
					}
				}

			}
		}

	}
</style>
